﻿Imports System

Namespace System.Workflow.Runtime.Tracking
    Friend NotInheritable Class TypeMatch
        ' Methods
        Private Sub New()
        End Sub

        Friend Shared Function IsMatch(ByVal obj As Object, ByVal name As String, ByVal matchDerived As Boolean) As Boolean
            Dim type As Type = obj.GetType
            If (String.Compare(type.Name, name, StringComparison.Ordinal) = 0) Then
                Return True
            End If
            If matchDerived Then
                If (Not type.GetInterface(name) Is Nothing) Then
                    Return True
                End If
                Dim type2 As Type = type.BaseType
                Do While (Not type2 Is Nothing)
                    If (String.Compare(type2.Name, name, StringComparison.Ordinal) = 0) Then
                        Return True
                    End If
                    type2 = type2.BaseType
                Loop
            End If
            Return False
        End Function

        Friend Shared Function IsMatch(ByVal obj As Object, ByVal matchType As Type, ByVal matchDerived As Boolean) As Boolean
            Return ((obj.GetType Is matchType) OrElse (matchDerived AndAlso matchType.IsInstanceOfType(obj)))
        End Function

    End Class
End Namespace

